/**
 * Created by Administrator on 15-6-29.
 */
var Calendar2 = (function(){
	var Calendar = RichBase.extend({
		statics : {},
		EVENTS : {
			"click" : {
				".close" : "onCloseClick",
				".title .lastmonth" : "onPrevmonthClick",
				".title .nextmonth" : "onNextmonthClick",
				".detail" : "onDateSelect"
			}
		},
		init : function(opt){
			this.type = opt.type || "todayValid";
			this.container = opt.container;
		},
		onCloseClick : function(that,e){
			that.close(null);
		},
		onNextmonthClick : function(that,e){
			var nextmonth = CalendarCore.nextMonth(that.currentDate);
			that.show(nextmonth);
		},
		onDateSelect : function(that,e){
			var tarDateBox = $(e.currentTarget);
			var currentDate = that.currentDate;
			if(currentDate.length==10) currentDate = currentDate.substring(0,7);
			var tarDate = tarDateBox.find(".dateNum").text();
			tarDate = currentDate+"-"+tarDate;
			that.fire("onSelect",tarDate);
			if(tarDateBox.hasClass("valid")){
				that.fire("onValidSelect",tarDate);
				that.close(tarDate);
			}else{
				that.fire("onUnvalidSelect",tarDate);
			}
		},
		onPrevmonthClick : function(that,e){
			var prevmonth = CalendarCore.prevMonth(that.currentDate);
			that.show(prevmonth);
		},
		show : function(date,type,callback){
			date = date || CalendarCore.gettoday();
			var type = this.type || "todayValid";
			this.container.show().html(CalendarCore.outputHtml(date,type));
			this.currentDate = date;
			callback && callback();
		},
		close : function(date,callback){
			this.container.hide();
			this.fire("onClose",date);
			callback && callback();
		}
	});
	return Calendar;
})();